home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / mcomm551.zip / TIMER.HPP < prev    next >
C/C++ Source or Header  |  1991-01-10  |  4KB  |  96 lines

  1.  
  2. /////////////////////////////////////////////////////////////////////////////
  3. //                                                                         //
  4. //  TIMER.HPP - header file for C++ programs using MCOMM timer functions.  //
  5. //    Zortech C++ 2.0, Turbo C++ 1.00 version.                             //
  6. //                                                                         //
  7. //  In order to use this class you must call the function 'tickhookset'    //
  8. //  with a non-zero argument.  This hooks interrupt vector 1C (timer       //
  9. //  tick) and enables the master tick variable.                            //
  10. //                                                                         //
  11. //                      * * *  W A R N I N G  * * *                        //
  12. //  BEFORE EXITING YOUR PROGRAM YOU MUST CALL tickhookset AGAIN WITH A     //
  13. //  ZERO ARGUMENT TO UNHOOK THE VECTOR.  Failing to do this will crash     //
  14. //  the operating system.                                                  //
  15. //                                                                         //
  16. //    Mike Dumdei,  6 Holly Lane,  Texarkana TX  75503    (c) 1989,1990    //
  17. //                                                                         //
  18. /////////////////////////////////////////////////////////////////////////////
  19.  
  20. #if !defined(TIMER_HPP)
  21. #define TIMER_HPP
  22.  
  23. //////////////////////////////
  24. //  Timer class definition  //
  25. //////////////////////////////
  26. class Timer
  27. {
  28.   private:
  29.     long TimeOutClock;              // instance variable
  30.   public:
  31.     Timer();                        // constructors
  32.     Timer(int Ticks);
  33.     Timer(unsigned int Ticks);
  34.     Timer(long Ticks);
  35.     Timer(unsigned long Ticks);
  36.     ~Timer();                       // destructor
  37.     void Set(int Ticks);            // set Timer functions
  38.     void Set(unsigned int Ticks);
  39.     void Set(long Ticks);
  40.     void Set(unsigned long Ticks);
  41.     void Delay(int Ticks);          // set delay functions
  42.     void Delay(unsigned int Ticks);
  43.     int Expired();                  // check for timer expired
  44.     unsigned long ReadTicks();      // read master tick count
  45. };
  46.  
  47. ////////////////////////////////////
  48. //  External low level functions  //
  49. ////////////////////////////////////
  50. #ifndef TIMER_H
  51.   extern "C" {
  52. int tickhookset(int flag);
  53. void set_timeout(Timer *timer, unsigned int ticks);
  54. void set_longtimeout(Timer *timer, long ticks);
  55. int timed_out(Timer *timer);
  56. void tdelay(unsigned int ticks);
  57. long get_ticker(void);
  58.   }
  59. #define TIMER_H
  60. #endif
  61.  
  62. //////////////////////////////////
  63. //  Timer class implementation  //
  64. //////////////////////////////////
  65. inline Timer::Timer()
  66.  { }
  67. inline Timer::Timer(int Ticks)
  68.  { set_timeout(this, (unsigned int)Ticks); }
  69. inline Timer::Timer(unsigned int Ticks)
  70.  { set_timeout(this, Ticks); }
  71. inline Timer::Timer(long Ticks)
  72.  { set_longtimeout(this, Ticks); }
  73. inline Timer::Timer(unsigned long Ticks)
  74.  { set_longtimeout(this, (long)Ticks); }
  75. inline Timer::~Timer()
  76.  { }
  77. inline void Timer::Set(int Ticks)
  78.  { set_timeout(this, (unsigned int)Ticks); }
  79. inline void Timer::Set(unsigned int Ticks)
  80.  { set_timeout(this, Ticks); }
  81. inline void Timer::Set(long Ticks)
  82.  { set_longtimeout(this, Ticks); }
  83. inline void Timer::Set(unsigned long Ticks)
  84.  { set_longtimeout(this, (long)Ticks); }
  85. inline void Timer::Delay(int Ticks)
  86.  { tdelay((unsigned int)Ticks); }
  87. inline void Timer::Delay(unsigned int Ticks)
  88.  { tdelay(Ticks); }
  89. inline int Timer::Expired()
  90.  { return timed_out(this); }
  91. inline unsigned long Timer::ReadTicks()
  92.  { return (unsigned long)get_ticker(); }
  93.  
  94. #endif          // TIMER_HPP
  95.  
  96.